<!DOCTYPE html>
<html>
  <head>
    <title>Listing 7.13</title>
    <script type="text/javascript" src="../scripts/assert.js"></script>
    <link href="../styles/assert.css" rel="stylesheet" type="text/css">
  </head>
  <body>
    <script type="text/javascript">

      function trim(str) {                          //#1
        var str = str.replace(/^\s\s*/, ''),
            ws = /\s/,
            i = str.length;
        while (ws.test(str.charAt(--i)));
        return str.slice(0, i + 1);
      }

      assert(trim(" #id div.class ") == "#id div.class",
          "Extra whitespace trimmed from a selector string.");

    </script>
  </body>
</html>
